use std::fmt::{Debug, Display};

pub trait Summary {
    fn summarize(&self) -> String;

    fn summarize_author(&self) -> String {
        format!("(i am {}...)", self.summarize())
    }
}

pub struct NewsArticle {
    pub headline: String,
    pub location: String,
    pub author: String,
    pub content: String,
}

pub struct Tweet {
    pub username: String,
    pub content: String,
    pub reply: bool,
    pub retweet: bool,
}

impl Summary for NewsArticle {
    fn summarize(&self) -> String {
        format!("{},{},{}", self.headline, self.author, self.location)
    }
    fn summarize_author(&self) -> String {
        format!("{},{},{}", self.headline, self.author, self.location)
    }
}

impl Summary for Tweet {
    fn summarize(&self) -> String {
        format!("{},{}", self.username, self.content)
    }
}

pub fn notify(item: impl Summary, item2: impl Summary) {
    println!("123456");
}

pub fn notify2(item: impl Summary + Display) {
    println!("123456");
}

pub fn notify1<T>(item: T, item2: T) {
    println!("123456");
}

pub fn notify3<T: Summary + Display>(item: T) {
    println!("123456");
}

pub fn notify4<T:Summary+Display,U: Clone + Debug>(a:T,b:U) {
}

pub fn notify5<T,U>(a:T,b:U)
where T:Summary+Display,
      U: Clone + Debug
{
}

pub fn notify6(s: &str) -> impl Summary {
    Tweet {
        username: String::from("horse_ebooks"),
        content: String::from("i love you, mike!"),
        reply: false,
        retweet: true,
    }
}

struct Pair<T> {
    x: T,
    y: T,
}

impl <T> Pair<T> {
    fn new(x: T,y: T) -> Self {
        Self {x,y}
    }
}

impl <T: Display + PartialOrd> Pair<T> {
    fn cmp_display(&self) {
        if self.x >= self.y {
            println!("{}",self.x);
        } else {
            println!("{}",self.y);
        }
    }
}

// 覆盖实现请看图的示例 2.jpg